import { selectOrder } from "../../../server/api";
import {openMap} from '../../../server/pulbmethod'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: "0",
    list: [],
    type: "0",
    pageNo: "1",
    pageSize: "10",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      list:[],
      pageNo:1
    })
    this.getdata();
  },
  //获取列表数据
 async getdata(res) {

    if (this.data.active == 0) {
      const params = {
        type: "0",
        userid: wx.getStorageSync("id"),
        pageNo:res == undefined ? this.data.pageNo : res.pageNo,
        pageSize:res == undefined ? this.data.pageSize : res.pageSize,
      };
      const  data = await selectOrder(params)
      const source = data.result.records
      this.setData({
        list:[...this.data.list,...source] ,
      });
    } else {
      const params = {
        type: "1",
        userid: wx.getStorageSync("id"),
        pageNo:res == undefined ? this.data.pageNo : res.pageNo,
        pageSize:res == undefined ? this.data.pageSize : res.pageSize,
      };
      const  data = await selectOrder(params)
      const source = data.result.records
      this.setData({
        list:[...this.data.list,...source] ,
      });
    }
  },
  //待核销和已核销切换
  onChange(e) {
    
    this.setData({ active: e.detail.name,list:[],pageNo:'1' });
    this.getdata();
  },
  //滚动条事件
  getMore() {
    this.data.pageNo++ 
    const params = {
      pageNo:this.data.pageNo,
      pageSize:this.data.pageSize
    }
    this.getdata(params)
  },
  detail(e) {
    const data = e.currentTarget.dataset.obj
    const ooj = {
      commodityName:data.commodityName,
      price:data.price,
      quantity:data.quantity,
      qrcode:data.qrcode,
      active:this.data.active,
      pscode:data.pscode
    }
    const list =  encodeURIComponent(JSON.stringify(ooj)) 

    wx.navigateTo({
      url: `/subPackagesA/pages/dimensionalcode/dimensionalcode?obj=${list}`,
    });
  },
   //打开地图
   openadd(e){
     if(this.data.active == 0)
      {
        const obj = e.currentTarget.dataset.meg
        openMap(obj)
      }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
